<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <link rel="stylesheet" href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.css">
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title></title>
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <script src="../script/api.js"></script>
    <style>
        .container-wrapper {
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            gap: 15px;
            margin-top: 20px;
            
        }

        .container {
            display: flex;
            flex-direction: column;
            justify-content: space-around;
            align-items: center;
            text-align: center;
            width: 40%;
            height: 90px;
            background-color: #fff;
            border: 1px solid #ddd;
            border-radius: 15px;
            padding: 16px;
            cursor: pointer;
            transition: transform 0.2s;
        }



        .container img {
            max-height: 30px;
            margin-bottom: 8px;
        }

        .task-text {
            font-size: 18px;
            font-weight: bold;
            color: #333;
        }
    </style>
</head>

<body>
    <header id='header' class="aui-bar aui-bar-nav" style="background-color: #03a9f4">
        <a class="aui-pull-left aui-btn" onclick="api.closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="middle">
            选择机台设备
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:0px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label" style="font-size: 14px;">设备编码</div>
                    <input type="text" class="aui-input" placeholder="请 扫描/输入 设备编码" style="width: 80%;font-size: 14px;"
                        id="equipCode" onfocus="focusFn(this)">

                </div>
            </li>

        </ul>
        <div style="width:100%;margin-top:2%;"></div>
        <div class="container-wrapper">
            <div class="container" onclick="toScanner();">
                <img src="../image/scann.png" alt="扫描查询图标">
                <div class="task-text">扫描查询</div>
            </div>
            <div class="container" onclick="doSearch()">
                <img src="../image/select.png" alt="输入查询图标">
                <div class="task-text">输入查询</div>
            </div>
        </div>
        <ul class="ui-selectee" id="tbodyHtml">

        </ul>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script>
    var type = "";
    apiready = function () {

        type = api.pageParam.type; //设备维保类型
        $("#equipCode").focus();
        idSelector = "equipCode";
        doSearch();
    }
    function toScanner() {
        var moduleScanner = api.require('moduleScanner');
        var params = {
            top: 150,//扫描窗口的上边距
            width: 250,//扫描窗口的宽
            height: 250,//扫描窗口的高
            useColor: false,//是否使用自己设定的颜色(startColor和endColor),
            //如果不使用设定的颜色就使用默认的那张网格图
            startColor: '#0F08C8FF',//渐变起始颜色
            endColor: '#7F08C8FF',//渐变结束颜色
            animTime: 2200,//扫描动画时间,单位为毫秒
        };
        moduleScanner.toScannerActivityForResult(params, function (ret, err) {
            var SMequipCode = ret;
            var text = document.getElementById("equipCode");
            text.value = SMequipCode;
            doSearch("Y")
        });

    }
    function focusFn(ele) {
        $api.attr(ele, 'readonly', 'readonly');
        setTimeout(() => {
            $api.removeAttr(ele, 'readonly');
        }, 200);
    };
    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    //查询
    function doSearch(flag) {
        //光标所在id
        var idSelector = "";
        //设备编码
        var equipCode = $("#equipCode").val();
        var equipmentno
        var equipCodes
        if (flag) {
            equipmentno = equipCode;
            equipCodes = '';
        } else {
            equipmentno = '';
            equipCodes = equipCode;
        }
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getEquipInfo";
        var data = {
            values: {
                equipmentno: equipmentno,
                equipCode: equipCodes,
                un: un
            }
        };

        api.showProgress({
            title: '查询中...',
        });
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {

                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        html += "<li class='sortable ui-selectee ui-sortable'>";
                        html += "<ul class='aui-list aui-media-list ui-selectee'>";
                        html += "<li class='aui-list-item  ui-selectee'>";
                        html += "<div class='aui-media-list-item-inner ui-selectee'>";
                        html += "<div class='aui-list-item-inner ui-selectee'>";
                        html += "<div class='aui-list-item-text ui-selectee'  style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>机台编号</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].equipmentno + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>机台名称</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].equipmentname + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title'>规格型号</div>";
                        html += "<div class='aui-list-item-inner ui-selectee'>" + list[i].model + "</div>";
                        html += "</div>";
                        html += "<div class='aui-list-item-text ui-selectee' style='height: 30px;'>";
                        html += "<div class='aui-list-item-label ui-selectee list-tr-title' style='width: 45%;'>类别</div>";
                        html += "<div class='aui-list-item-inner ui-selectee' style='margin-left: 0.1rem;'>" + list[i].type + "</div>";
                        html += "<div class='aui-list-item-right aui-btn ui-selectee' " +
                            "onclick='goPageDetail(\"" + list[i].equipmentno + "\",\"" + list[i].equipmentname + "\");'>选择</div>";
                        html += "</div>";
                        html += "</div>";
                        html += "</div>";
                        html += "</li>";
                        html += "</ul>";
                        html += "</li>";
                    }
                    $api.html($api.byId("tbodyHtml"), html);
                    $("#equipCode").focus();
                    idSelector = "equipCode";
                    api.hideProgress();
                    //失败
                } else if (myobj.code == "1") {
                    //清空表格数据
                    api.hideProgress();
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                } else {
                    api.hideProgress();
                }

            } else {
                api.hideProgress();
                alert("连接超时，请耐心等待");
            }
        });
    }

    //跳转详情页面
    function goPageDetail(equipmentno, equipmentname) {
        //打开页面
        api.openWin({
            name: 'selectEquipTaskInfo',
            url: 'selectEquipTaskInfo' + '.html',
            pageParam: {
                equipmentno: equipmentno,
                equipmentname: equipmentname,
                type: type,
            },
        });
    }

    //刷新数据
    function refreshData() {
        doSearch();
    }
</script>

</html>